package interview.huawei.training.p41;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNextInt()) {
            // 砝码的种数
            int weightKinds = scanner.nextInt();
            // 每种砝码的重量
            int[] weights = new int[weightKinds];
            for(int i = 0; i < weightKinds; i++) {
                weights[i] = scanner.nextInt();
            }
            // 每种砝码的个数
            int[] weightCounts = new int[weightKinds];
            for(int i = 0; i < weightKinds; i++) {
                weightCounts[i] = scanner.nextInt();
            }
            // 每种砝码可能的总重量
            ArrayList<Integer> allWeights = new ArrayList<>();
            for(int i = 0; i < weightKinds; i++) {
                // 遍历砝码的个数
                for(int j = 0; j < weightCounts[i]; j++) {
                    // 砝码的重量 * 砝码的个数
                    allWeights.add(weights[i]);
                }
            }
            // System.out.println(allWeights);
            // 遍历所有砝码
            System.out.println(getPossibleTotal(allWeights.toArray(new Integer[0]), 0, 0, new HashSet<Integer>(), 0));
        }
        
    }

    private static int getPossibleTotal(Integer[] possbileWeights, int length, int startIndex, HashSet<Integer> totalWeights, int totalWeight) {
        int count = 0;
        if (!totalWeights.contains(totalWeight)) {
            totalWeights.add(totalWeight);
            count++;
        }

        for (int i = startIndex; i < possbileWeights.length; i++) {
            count += getPossibleTotal(possbileWeights, length + 1, i + 1, totalWeights, totalWeight + possbileWeights[i]);
        }

        return count;
    }
}